element_name = ['H', 'He', 'Li', 'Be', 'B', 'C', 'N', 'O', 'F', 'Ne', 'Na', 'Mg', 'Al', 'Si', 'P', 'S', 'Cl', 'Ar', 'K', 'Ca', 'Sc', 'Ti', 'V', 'Cr', 'Mn', 'Fe', 'Co', 'Ni', 'Cu', 'Zn', 'Ga', 'Ge', 'As', 'Se', 'Br', 'Kr', 'Rb', 'Sr', 'Y', 'Zr', 'Nb', 'Mo', 'Tc', 'Ru', 'Rh', 'Pd', 'Ag', 'Cd', 'In', 'Sn', 'Sb', 'Te', 'I', 'Xe', 'Cs', 'Ba', 'La', 'Ce', 'Pr', 'Nd', 'Pm', 'Sm', 'Eu', 'Gd', 'Tb', 'Dy', 'Ho', 'Er', 'Tm', 'Yb', 'Lu', 'Hf', 'Ta', 'W', 'Re', 'Os', 'Ir', 'Pt', 'Au', 'Hg', 'Tl', 'Pb', 'Bi', 'Po', 'At', 'Rn', 'Fr', 'Ra', 'Ac', 'Th', 'Pa', 'U', 'Np', 'Pu', 'Am', 'Cm', 'Bk', 'Cf', 'Es', 'Fm', 'Md', 'No', 'Lr', 'Rf', 'Db', 'Sg', 'Bh', 'Hs', 'Mt', 'Ds']
element_ar = [1, 4, 7, 9, 11, 12, 14, 16, 19, 20, 23, 24, 27, 28, 31, 32, 35.5, 40, 39, 40, 45, 48, 51, 52, 55, 56, 59, 59, 64, 65, 70, 73, 75, 79, 80, 84, 85, 88, 89, 91, 93, 96, 99, 101, 103, 106, 108, 112, 115, 119, 122, 128, 127, 131, 133, 137, 139, 140, 141, 144, 145, 150, 152, 157, 159, 162.5, 165, 167, 169, 173, 175, 178, 181, 184, 186, 190, 192, 195, 197, 201, 204, 207, 209, 209, 210, 222, 223, 226, 227, 232, 231, 238, 237, 244, 243, 247, 247, 251, 254, 257, 258, 259, 260, 261, 262, 263, 262, 265, 266, 269]

def group_det(num): 
	if(num == 1 or num == 3 or num == 11 or num == 19 or num == 29 or num == 37 or num == 47 or num == 55 or num == 79 or num == 87):
		return 1
	elif(num == 4 or num == 12 or num == 20 or num == 30 or num == 38 or num == 48 or num == 56 or num == 80 or num == 88):
		return 2
	elif(num == 5 or num == 13 or num == 21 or num == 31 or num == 39 or num == 49 or num == 57 or num == 81 or num == 89):
		return 3
	elif(num == 6 or num == 14 or num == 22 or num == 32 or num == 40 or num == 50 or num == 72 or num == 82 or num == 104):
		return 4
	elif(num == 7 or num == 15 or num == 23 or num == 33 or num == 41 or num == 51 or num == 73 or num == 83 or num == 105):
		return 5
	elif(num == 8 or num == 16 or num == 24 or num == 34 or num == 42 or num == 52 or num == 74 or num == 84 or num == 106):
		return 6
	elif(num == 9 or num == 17 or num == 25 or num == 35 or num == 43 or num == 53 or num == 75 or num == 85 or num == 107):
		return 7
	elif(num == 2 or num == 10 or num == 18 or num == 26 or num == 27 or num == 28 or num == 36 or num == 44 or num == 45 or num == 46 or num == 54 or num == 76 or num == 77 or num == 78 or num == 86 or num == 108 or num == 109 or num == 110):
		return 8
	elif(57 < num < 72):
		return 9
	elif(89 < num < 104):
		return 10

def period_det(num):
	if(0 < num < 3):
		return 1
	elif(2 < num < 11):
		return 2
	elif(10 < num < 19):
		return 3
	elif(18 < num < 37):
		return 4
	elif(36 < num < 55):
		return 5
	elif(54 < num < 87):
		return 6
	elif(86 < num < 111):
		return 7

def row_det(num):
	if(0<num<3):
		return 1
	elif(3 < num < 11):
		return 2
	elif(10 < num < 19):
		return 3
	elif(18 < num < 29):
		return 4
	elif(28 < num < 37):
		return 5
	elif(36 < num < 47):
		return 6
	elif(46 < num < 55):
		return 7
	elif(54 < num < 79):
		return 8
	elif(78 < num < 87):
		return 9
	elif(86 < num < 111):
		return 10

def e_formula(group, period, row, num):
	if(group == 1 and period == 1):
		return '1S[1]'
	elif(group == 8 and period == 1):
		return '1S[2]'
	elif(period == 2):
		if(0 < group < 3):
			return '2S[' + str(group)  + ']'
		elif(2 < group < 9):
			return '2S[2]2P[' +  str(group - 2) + ']'
	elif(period == 3):
		if(0 < group < 3):
			return '3S[' + str(group)  + ']'
		elif(3 < group < 9):
			return '3S[2]3P[' +  str(group - 2) + ']'
	elif(row == 4 and group != 8):
		if(0 < group < 3):
			return '4S[' + str(group)  + ']'
		elif(2 < group < 9):
			return '4S[2]3d[' +  str(group - 2) + ']'
	elif(row == 4 and group == 8):
		return '4S[2]3d[' +  str(num - 20) + ']'
	elif(row == 5):
		if(0 < group < 3):
			return '4S[2]3d[' + str(group + 8)  + ']'
		elif(2 < group < 9):
			return '4S[2]3d[10]4P[' +  str(group - 2) + ']'
	elif(row == 6 and group != 8):
		if(0 < group < 3):
			return '5S[' + str(group) + ']'
		elif(2 < group < 9):
			return '5S[2]4d[' + str(group - 2) + ']'
	elif(row == 6 and group == 8):
		return '4S[2]3d[' +  str(num - 32) + ']'
	elif(row == 7):
		if(0 < group < 3):
			return '5S[2]4d[' + str(group + 8)  + ']'
		elif(2 < group < 9):
			return '5S[2]4d[10]5P[' +  str(group - 2) + ']'
	elif(row == 8 and group != 8):
		if(0 < group < 3):
			return '6S[' + str(group) + ']'
		elif(2 < group < 4):
			return '6S[2]5d[1]'
		elif(group == 9):
			return '6S[2]5d[1]4f[' + str(num - 57) + ']'
		elif(3 < group < 9):
			return '6S[2]5d[' + str(group - 2) + ']4f[14]'
	elif(row == 8 and group == 8):
		return '6S[2]5d[' + str(num - 70) + ']4f[14]'
	elif(row == 9):
		if(0 < group < 3):
			return '6S[2]5d[' + str(group + 8)  + ']4f[14]'
		elif(2 < group < 9):
			return '6S[2]5d[10]4f[14]6P[' + str(group - 2) + ']'
	elif(row == 10 and group != 8):
		if(0 < group < 3):
			return '7S[' + str(group) + ']'
		elif(2 < group < 5):
			return '7S[2]6d[' + str(group - 2) + ']'
		elif(group == 10):
			return '7S[2]6d[1]5f[' + str(num - 89) + ']'
		elif(3 < group < 9):
			return '7S[2]6d[' + str(group - 2) + ']5f[14]'
	elif(row == 10 and group == 8):
		return '7S[2]6d[' + str(num - 102) + ']5f[14]'

def chem(num):
	name = element_name[num - 1]
	N = element_ar[num] - num
	group = group_det(num)
	period = period_det(num)
	row = row_det(num)
	e_form = e_formula(group, period, row, num)

	if(group == 9):
		group = "Это лантаноид"
	elif(group == 10):
		group = "Это актиноид"

	print("\nИмя элемента: " + name)
	print("Количество электронов: " + str(num))
	print("Количество протонов: " + str(num))
	print("Относительная атомная масса: " + str(element_ar[num - 1]))
	print("Количество нейтронов: " + str(N))
	print("Номер группы: " + str(group))
	print("Номер периода: " + str(period))
	print("Электронная формула: " + e_form)
	input("\nНажмите Enter чтобы выйти...")